package com.java.tutorials.jdk7.database;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.Types;
/**
 * Created by xuzhike on 2016/1/23.
 * http://www.java2s.com/Code/Java/JDK-7/ControllingthetypevalueoftheOUTparameter.htm
 * 需要添加存储过程
 */
public class OutParameterTypeTest {
    public static void main(String[] args) throws Exception {
        Connection conn = DriverManager
                .getConnection("jdbc:mysql://localhost:3306/pssm", "root", "");
        String query = "{CALL GETDATE(?,?)}";
        CallableStatement callableStatement = (CallableStatement) conn
                .prepareCall(query);

        callableStatement.setInt(1, 123);
        callableStatement.registerOutParameter(2, Types.DATE);
        callableStatement.executeQuery();

        Date date = callableStatement.getObject(2, Date.class);
        System.out.println("date = "+date);

    }
}
